import { EToplistType } from "../../../../Message/Public/EToplistType";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { Cache } from "../../cache/Cache";
type int = number;
//class RankingInfo
    
    export  class RankingInfo
    {
        constructor(arg1: int)
        {
            
            this._rankingData = [];
            this.array = [];
            this._type = arg1;
            var loc1=this._type;
            switch (loc1) 
            {
                case EToplistType._EToplistTypeGuildLevel: case EToplistType._EToplistTypeGuildAsset: case EToplistType._EToplistTypeGuildWarGuildMark: case EToplistType._EToplistTypeGuildWarGuildMarkWeek:
                {
                    this.isSex = false;
                    this.isCareer = false;
                    this.isSociaty = true;
                    break;
                }
                case EToplistType._EToplistTypeCopyMagicTower: case EToplistType._ETopListTypeCopyTowerSixty: case EToplistType._EToplistTypePetTalent: case EToplistType._EToplistTypePetGrowth: case EToplistType._EToplistTypePetSpirit: case EToplistType._EToplistTypeGuildWarPlayerMerits:
                {
                    this.isSex = false;
                    this.isCareer = false;
                    break;
                }
                case EToplistType._EToplistTypeFlowerWeekProtect: case EToplistType._EToplistTypeFlowerWeek: case EToplistType._EToplistTypeFlowerProtect: case EToplistType._EToplistTypeFlower:
                {
                    this.isSex = false;
                    break;
                }
                case EToplistType._EToplistTypeWeaponScore: case EToplistType._EToplistTypeJewelryScore: case EToplistType._EToplistTypeArmorScore:
                {
                    this.isSex = false;
                    break;
                }
            }
            return;
        }

        public set rankingData(arg1: Array<any>)
        {
            this._rankingData = arg1;
            this.selfRank = this.getSelfRank();
            if (arg1 && arg1.length) 
            {
                this.createDate = (arg1[0] as TToplist).createDt;
            }
            return;
        }

        public get rankingData(): Array<any>
        {
            return this._rankingData;
        }

        public get type(): int
        {
            return this._type;
        }

        public getDataByPage(arg1: int, arg2: int=1, arg3: int=0, arg4: int=-1, arg5: int=-1, arg6: int=10): Array<any>
        {
            if (arg1 <= 0) 
            {
                return [];
            }
            var loc1=[];
            var loc2=(arg2 - 1) * arg6;
            var loc3=arg2 * arg6;
            loc1 = this.getDataByCamp(this._rankingData.concat(), arg3, arg1);
            if (this.isCareer) 
            {
                loc1 = this.getDataByCareer(loc1, arg4);
            }
            if (this.isSex) 
            {
                loc1 = this.getDataBySex(loc1, arg5);
            }
            var loc4=loc1.length;
            this.setMaxPage(loc4);
            return loc1 = loc1.slice(loc2, loc3);
        }

        /* internal  */getDataByCamp(arg1: Array<any>, arg2: int, arg3: int): Array<any>
        {
            var loc2=0;
            var loc1=[];
            if (arg2 != 0) 
            {
                loc2 = 0;
                while (loc2 < arg1.length) 
                {
                    if (arg1[loc2].propertyOne == arg2) 
                    {
                        loc1.push(arg1[loc2]);
                    }
                    ++loc2;
                }
            }
            else 
            {
                loc1 = arg1;
            }
            return loc1;
        }

        /* internal  */getDataBySex(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            if (arg2 != -1) 
            {
                var loc3=0;
                var loc4=arg1;
                for(loc2 of loc4) 
                {
                    if (loc2.propertyTwo != arg2) 
                    {
                        continue;
                    }
                    loc1.push(loc2);
                }
            }
            else 
            {
                loc1 = arg1;
            }
            return loc1;
        }

        /* internal  */getDataByCareer(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc2=null;
            var loc1=[];
            if (arg2 != -1) 
            {
                var loc3=0;
                var loc4=arg1;
                for(loc2 of loc4) 
                {
                    if (loc2.propertyThree != arg2) 
                    {
                        continue;
                    }
                    loc1.push(loc2);
                }
            }
            else 
            {
                loc1 = arg1;
            }
            return loc1;
        }

        /* internal  */setMaxPage(arg1: int, arg2: int=10): void
        {
            var loc1=arg1 % arg2;
            if (loc1 == 0) 
            {
                this.curMaxPage = arg1 / arg2;
            }
            else 
            {
                this.curMaxPage = arg1 / arg2 + 1;
            }
            return;
        }

        public isInRankingByName(arg1: int, arg2: string): int
        {
            var loc2=null;
            var loc4=0;
            var loc1=0;
            var loc3=this._rankingData.length;
            loc4 = 0;
            while (loc4 < loc3) 
            {
                if ((loc2 = this._rankingData[loc4]).entityName == arg2) 
                {
                    loc1 = loc2.rank;
                    break;
                }
                ++loc4;
            }
            return loc1;
        }

        /* internal  */getSelfRank(): int
        {
            var loc2=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc1=0;
            if (this._rankingData == null) 
            {
                return 0;
            }
            var loc3=this._rankingData.length;
            if (this.isSociaty) 
            {
                loc6 = "";
                if ((loc7 = Cache.instance.guild.myGuildInfo) != null) 
                {
                    loc6 = loc7.guildName;
                    loc4 = 0;
                    while (loc4 < loc3) 
                    {
                        loc2 = this._rankingData[loc4];
                        if (loc2.entityName == loc6) 
                        {
                            loc1 = loc2.rank;
                        }
                        ++loc4;
                    }
                }
            }
            else 
            {
                loc5 = Cache.instance.role.entityInfo.name;
                loc4 = 0;
                while (loc4 < loc3) 
                {
                    loc2 = this._rankingData[loc4];
                    if (loc2.entityName == loc5) 
                    {
                        loc1 = loc2.rank;
                        break;
                    }
                    ++loc4;
                }
            }
            return loc1;
        }

        public /* var */selfRank: int;

        public /* var */curMaxPage: int;

        public /* var */createDate: Date;

        /* internal */ /* var */_rankingData: Array<any>;

        public /* var */isSex: Boolean=true;

        public /* var */isCareer: Boolean=true;

        public /* var */isCarer: Boolean=true;

        public /* var */isSociaty: Boolean=false;

        /* internal */ /* var */_type: int;

        public /* var */array: Array<any>;
    }
